from PySide6.QtWidgets import QDialog,QMessageBox
from views.schoolInfo.schoolinfo import Ui_addschoolinfo
from sqlalchemy.orm import Session
from settings.publicvar import engine
from views.schoolInfo.model.SchoolInfo import CreateSchoolInfo
class SchoolInfoView(QDialog,Ui_addschoolinfo):
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        self.savebtn.clicked.connect(self.addschoolinfo)
        self.exec()

    def addschoolinfo(self):
        name = self.name.text().strip()
        schoolnum = self.schoolnum.text().strip()
        mark = self.mark.text().strip()
        if name == '' or schoolnum == '' or mark == '':
            QMessageBox.critical(None, '添加失败', '学校、编码不能为空！')
        else:
            with Session(engine) as session,session.begin():
                school = CreateSchoolInfo(name=name,schoolid=schoolnum,maker=mark)
                session.add(school)
                QMessageBox.critical(None,'添加成功','恭喜学校添加成功！')
                self.hide()